import { IFeidaoAiBrowserComponent } from '@dfeidao/atom-web/interfaces';
import local_get from '@dfeidao/atom-web/local/get';

import fire from '@dfeidao/atom-web/msg/fire';
import nodejs from '@dfeidao/atom-web/msg/nodejs';
import msg_error from '@dfeidao/atom-web/msgbox/error';
import msg_success from '@dfeidao/atom-web/msgbox/success';
import storage_get from '@dfeidao/atom-web/storage/get';

// 初始化功能定义
export default async function a003(fd: IFeidaoAiBrowserComponent) {
	const group_name = fd.data.node.querySelector<HTMLInputElement>('[data-feidao-name="group_names"]').value;
	const productid = await storage_get('productid');
	const client_type = local_get(fd, 'client_type') as string;
	const old_name = local_get(fd, 'group_name') as string;
	const group_number = local_get(fd, 'group_number') as string;
	// debugger;
	if (!group_name) {
		msg_error('功能分组名称不能为空！');
		return;
	}
	if (old_name === group_name) {
		msg_error('功能分组名称不能相同，请重新输入！');
		return;
	} else {
		const res = await nodejs('function-definition/zj-000010/s001', { group_name, productid, client_type, group_number });
		if (res === 'success') {
			msg_success('修改成功');
			fd.data.node.classList.add('display-n');
			fire('zj-000001', 'a013', { client_type });
		} else {
			msg_error('修改失败！');
			return;
		}

	}

}
